package com.jia.controller;


import com.jia.common.lang.R;
import com.jia.entity.ChatFriendApply;
import com.jia.entity.SysUser;
import com.jia.service.ChatFriendApplyService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-05-30
 */
@RestController
@RequestMapping("/admin/chat/friendApply")
@Api(tags = "好友申请管理")
public class ChatFriendApplyController {

    @Autowired
    private ChatFriendApplyService chatFriendApplyService;

    @GetMapping("/getListByUserId/{userId}")
    public R getListByUserId(@PathVariable String userId) {
        List<SysUser> list = chatFriendApplyService.getListByUserId(userId);
        return R.ok().data("list",list);
    }

    @GetMapping("/agree")
    public R agree(@RequestParam String fromId,@RequestParam String toId) {
        chatFriendApplyService.agree(fromId,toId);
        return R.ok().message("添加好友成功");
    }

    @GetMapping("/reject")
    public R reject(@RequestParam String fromId,@RequestParam String toId) {
        chatFriendApplyService.reject(fromId,toId);
        return R.ok().message("拒绝好友申请");
    }

    @GetMapping("/list")
    public R list() {
        List<ChatFriendApply> list = chatFriendApplyService.list();
        return R.ok().data("list",list);
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        ChatFriendApply byId = chatFriendApplyService.getById(id);
        return R.ok().data("data",byId);
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id){
        chatFriendApplyService.removeById(id);
        return R.ok().message("删除成功");
    }

    @PostMapping("/save")
    public R save(@RequestBody ChatFriendApply chatFriendApply) {
        chatFriendApplyService.save(chatFriendApply);
        return R.ok().message("新增成功");
    }

    @PutMapping("/update")
    public R update(@RequestBody ChatFriendApply chatFriendApply){
        chatFriendApplyService.updateById(chatFriendApply);
        return R.ok().message("修改成功");
    }
}

